<template>
	<view class="content">
		<view class="info_list_title">情况上报</view>
		<view class="form">
			<u-form :model="form" ref="uForm">
			    
				<view>
					<u-form-item border="true" label="记录标题:" label-width="auto">
						<u-input v-model="title" />
					</u-form-item>
					<u-form-item border="true" label="发生时间:" label-width="auto">
						<u-input v-model="recordDate" @click="selectDate()" type="text" :border=border  placeholder="请选择时间"/>
					</u-form-item>
					<u-form-item border="true" label="地点:" label-width="auto">
						<u-input v-model="area" @click="selectArea()" type="text" :border=border  placeholder="请选择地区"/>
					</u-form-item>

					<view v-for="(item,index) in fields">
						<u-form-item :label="item.labelName+':'" label-width="auto" v-if="item.type==5">
							<u-input v-model="form[item.id]"  :placeholder="item.placeholder" />
						</u-form-item>
						<u-form-item label-position="top" :label="item.labelName+':'" label-width="auto" v-if="item.type==4">
							<u-input v-model="form[item.id]" :border="true" auto-height="true" type="textarea"  :placeholder="item.placeholder" />
						</u-form-item>
					</view>
					<view>
						<u-form-item border="true" label="附件上传:" label-width="auto">
							<u-upload ref="uUpload" :form-data="updata" :action="action" :before-upload="beforeUpload" :file-list="fileList" ></u-upload>
						</u-form-item>
					</view>

					
					
					
				</view>
				
				<u-button type="primary" style class="u-margin-top-40" @click="submit()">提交</u-button>

			</u-form>


		</view>
			<u-calendar v-model="calendarShow" :mode="calendarMode" @change="dateChange"></u-calendar>
		    <u-select v-model="areaShow" mode="mutil-column-auto" :list="areaList" @confirm="areaConfirm"></u-select>
	</view>
</template>

<script>
	import request from '../../util/request.js'
	import api from '../../util/api.js'
	import check from '../../util/check.js'
	export default {
		data() {
			return {
				id:'',
				fields:[
					
				],
				title:'',
				recordDate:'',
				form: {
					
				},
				calendarMode:'date',
				calendarShow:false,
				userInfo:null,
				labelPosition: 'left',
				border: false,
				action: api.upload,
				areaList: [{label:"山东省",level:1,value:37,parentId:0,children:[{label:"济南市",level:2,latitude:36.651216,value:3701,parentId:37,longitude:117.119999,children:[{label:"历下区",value:370102,parentId:3701},{label:"市中区",value:370103,parentId:3701},{label:"槐荫区",value:370104,parentId:3701},{label:"天桥区",value:370105,parentId:3701},{label:"历城区",latitude:36.680017,value:370112,parentId:3701,longitude:117.065237},{label:"长清区",value:370113,parentId:3701},{label:"平阴县",latitude:36.289265,value:370124,parentId:3701,longitude:116.456187},{label:"济阳区",latitude:36.978537,value:370125,parentId:3701,longitude:117.173525},{label:"商河县",latitude:37.309045,value:370126,parentId:3701,longitude:117.157183},{label:"济南高新技术产业开发区",value:370171,parentId:3701},{label:"莱芜区",latitude:36.213813,value:370173,parentId:3701,longitude:117.676723},{label:"钢城区",value:370174,parentId:3701},{label:"莱芜高新区",value:370175,parentId:3701},{label:"章丘区",value:370181,parentId:3701},{label:"南部山区",value:370190,parentId:3701},{label:"先行区",value:370191,parentId:3701}]},{label:"青岛市",level:2,latitude:36.067082,value:3702,parentId:37,longitude:120.382639,children:[{label:"市南区",value:370202,parentId:3702},{label:"市北区",value:370203,parentId:3702},{label:"西海岸新区",latitude:35.872664,value:370211,parentId:3702,longitude:120.04619},{label:"崂山区",value:370212,parentId:3702},{label:"李沧区",value:370213,parentId:3702},{label:"城阳区",latitude:36.307064,value:370214,parentId:3702,longitude:120.39631},{label:"开发区",value:370251,parentId:3702},{label:"保税港区",value:370252,parentId:3702},{label:"蓝谷",value:370253,parentId:3702},{label:"高新区",value:370255,parentId:3702},{label:"胶州市",latitude:36.26468,value:370281,parentId:3702,longitude:120.033382},{label:"即墨区",latitude:36.389639,value:370282,parentId:3702,longitude:120.447128},{label:"平度市",latitude:36.776358,value:370283,parentId:3702,longitude:119.98842},{label:"莱西市",latitude:36.889084,value:370285,parentId:3702,longitude:120.51769}]},{label:"淄博市",level:2,latitude:36.811814,value:3703,parentId:37,longitude:118.058258,children:[{label:"淄川区",value:370302,parentId:3703},{label:"张店区",value:370303,parentId:3703},{label:"博山区",value:370304,parentId:3703},{label:"临淄区",value:370305,parentId:3703},{label:"周村区",value:370306,parentId:3703},{label:"桓台县",value:370321,parentId:3703},{label:"高青县",value:370322,parentId:3703},{label:"沂源县",value:370323,parentId:3703},{label:"淄博高新区",value:370350,parentId:3703},{label:"淄博文昌湖区",value:370351,parentId:3703},{label:"淄博经开区",value:370352,parentId:3703}]},{label:"枣庄市",level:2,latitude:34.810487,value:3704,parentId:37,longitude:117.323725,children:[{label:"市中区",value:370402,parentId:3704},{label:"薛城区",value:370403,parentId:3704},{label:"峄城区",latitude:34.773263,value:370404,parentId:3704,longitude:117.590816},{label:"台儿庄区",value:370405,parentId:3704},{label:"山亭区",latitude:35.099528,value:370406,parentId:3704,longitude:117.461517},{label:"滕州市",value:370481,parentId:3704},{label:"枣庄高新区",value:370490,parentId:3704}]},{label:"东营市",level:2,latitude:37.433418,value:3705,parentId:37,longitude:118.674839,children:[{label:"东营区",value:370502,parentId:3705},{label:"河口区",value:370503,parentId:3705},{label:"垦利区",value:370505,parentId:3705},{label:"利津县",value:370522,parentId:3705},{label:"广饶县",value:370523,parentId:3705},{label:"东营经济技术开发区",value:370571,parentId:3705},{label:"东营港经济开发区",value:370572,parentId:3705},{label:"东营现代畜牧业示范区",value:370573,parentId:3705},{label:"黄河三角洲农业高新技术产业示范区",value:370574,parentId:3705}]},{label:"烟台市",level:2,latitude:37.463822,value:3706,parentId:37,longitude:121.447935,children:[{label:"芝罘区",value:370602,parentId:3706},{label:"福山区",value:370611,parentId:3706},{label:"牟平区",latitude:37.386901,value:370612,parentId:3706,longitude:121.600512},{label:"莱山区",value:370613,parentId:3706},{label:"长岛县",value:370634,parentId:3706},{label:"烟台高新技术产业开发区",value:370671,parentId:3706},{label:"烟台经济技术开发区",value:370672,parentId:3706},{label:"龙口市",value:370681,parentId:3706},{label:"莱阳市",latitude:36.978941,value:370682,parentId:3706,longitude:120.711673},{label:"莱州市",latitude:37.177017,value:370683,parentId:3706,longitude:119.942327},{label:"蓬莱市",latitude:37.810661,value:370684,parentId:3706,longitude:120.758848},{label:"招远市",latitude:37.355469,value:370685,parentId:3706,longitude:120.434072},{label:"栖霞市",latitude:37.335123,value:370686,parentId:3706,longitude:120.849675},{label:"海阳市",latitude:36.776378,value:370687,parentId:3706,longitude:121.158434}]},{label:"潍坊市",level:2,latitude:36.706774,value:3707,parentId:37,longitude:119.161755,children:[{label:"潍城区",value:370702,parentId:3707},{label:"寒亭区",value:370703,parentId:3707},{label:"坊子区",value:370704,parentId:3707},{label:"奎文区",value:370705,parentId:3707},{label:"临朐县",value:370724,parentId:3707},{label:"昌乐县",latitude:36.706945,value:370725,parentId:3707,longitude:118.829914},{label:"潍坊滨海经济技术开发区",value:370772,parentId:3707},{label:"潍坊经济技术开发区",value:370773,parentId:3707},{label:"潍坊国家高新技术开产业发区",value:370774,parentId:3707},{label:"峡山生态经济开发区",value:370775,parentId:3707},{label:"青州市",value:370781,parentId:3707},{label:"诸城市",value:370782,parentId:3707},{label:"寿光市",value:370783,parentId:3707},{label:"安丘市",latitude:36.478494,value:370784,parentId:3707,longitude:119.218978},{label:"高密市",value:370785,parentId:3707},{label:"昌邑市",latitude:36.85882,value:370786,parentId:3707,longitude:119.398525}]},{label:"济宁市",level:2,latitude:35.414921,value:3708,parentId:37,longitude:116.587098,children:[{label:"任城区",value:370811,parentId:3708},{label:"兖州区",value:370812,parentId:3708},{label:"微山县",value:370826,parentId:3708},{label:"鱼台县",value:370827,parentId:3708},{label:"金乡县",value:370828,parentId:3708},{label:"嘉祥县",latitude:35.407829,value:370829,parentId:3708,longitude:116.342442},{label:"汶上县",latitude:35.732799,value:370830,parentId:3708,longitude:116.489043},{label:"泗水县",latitude:35.664323,value:370831,parentId:3708,longitude:117.251195},{label:"梁山县",latitude:35.802306,value:370832,parentId:3708,longitude:116.096044},{label:"济宁高新技术产业开发区",value:370871,parentId:3708},{label:"曲阜市",value:370881,parentId:3708},{label:"邹城市",value:370883,parentId:3708}]},{label:"泰安市",level:2,latitude:36.200252,value:3709,parentId:37,longitude:117.087614,children:[{label:"泰山区",latitude:36.192084,value:370902,parentId:3709,longitude:117.135354},{label:"岱岳区",latitude:36.18799,value:370911,parentId:3709,longitude:117.041582},{label:"宁阳县",latitude:35.758787,value:370921,parentId:3709,longitude:116.805797},{label:"东平县",latitude:35.937102,value:370923,parentId:3709,longitude:116.470304},{label:"新泰市",latitude:35.909032,value:370982,parentId:3709,longitude:117.767953},{label:"肥城市",latitude:36.182572,value:370983,parentId:3709,longitude:116.768358},{label:"泰山景区",value:370990,parentId:3709},{label:"高新区",value:370997,parentId:3709}]},{label:"威海市",level:2,latitude:37.513068,value:3710,parentId:37,longitude:122.120419,children:[{label:"环翠区",value:371002,parentId:3710},{label:"文登区",latitude:37.193886,value:371003,parentId:3710,longitude:122.057941},{label:"威海火炬高技术产业开发区",value:371071,parentId:3710},{label:"威海经济技术开发区",value:371072,parentId:3710},{label:"威海临港经济技术开发区",value:371073,parentId:3710},{label:"威海南海新区",value:371076,parentId:3710},{label:"荣成市",latitude:37.16516,value:371082,parentId:3710,longitude:122.486658},{label:"乳山市",latitude:36.919816,value:371083,parentId:3710,longitude:121.539765}]},{label:"日照市",level:2,latitude:35.416377,value:3711,parentId:37,longitude:119.526888,children:[{label:"东港区",latitude:35.425475,value:371102,parentId:3711,longitude:119.462228},{label:"岚山区",latitude:35.121884,value:371103,parentId:3711,longitude:119.318929},{label:"五莲县",value:371121,parentId:3711},{label:"莒县",latitude:35.579868,value:371122,parentId:3711,longitude:118.837064},{label:"日照经济技术开发区",value:371171,parentId:3711}]},{label:"临沂市",level:2,latitude:35.104672,value:3713,parentId:37,longitude:118.356448,children:[{label:"兰山区",value:371302,parentId:3713},{label:"罗庄区",latitude:34.996741,value:371311,parentId:3713,longitude:118.284786},{label:"河东区",latitude:35.089917,value:371312,parentId:3713,longitude:118.402893},{label:"沂南县",latitude:35.549976,value:371321,parentId:3713,longitude:118.465213},{label:"郯城县",latitude:34.613557,value:371322,parentId:3713,longitude:118.367263},{label:"沂水县",latitude:35.79045,value:371323,parentId:3713,longitude:118.627918},{label:"兰陵县",latitude:34.857149,value:371324,parentId:3713,longitude:118.07065},{label:"费县",latitude:35.265961,value:371325,parentId:3713,longitude:117.977325},{label:"平邑县",latitude:35.505943,value:371326,parentId:3713,longitude:117.640352},{label:"莒南县",latitude:35.174846,value:371327,parentId:3713,longitude:118.835163},{label:"蒙阴县",latitude:35.710032,value:371328,parentId:3713,longitude:117.945085},{label:"临沭县",latitude:34.919852,value:371329,parentId:3713,longitude:118.650782},{label:"临沂高新技术产业开发区",value:371371,parentId:3713},{label:"临沂经济技术开发区",value:371372,parentId:3713},{label:"临沂临港经济开发区",value:371373,parentId:3713},{label:"农高区",value:371374,parentId:3713},{label:"蒙山",value:371375,parentId:3713}]},{label:"德州市",level:2,latitude:37.434092,value:3714,parentId:37,longitude:116.357464,children:[{label:"德城区",value:371402,parentId:3714},{label:"陵城区",latitude:37.335794,value:371403,parentId:3714,longitude:116.576092},{label:"宁津县",latitude:37.65219,value:371422,parentId:3714,longitude:116.800306},{label:"庆云县",latitude:37.77535,value:371423,parentId:3714,longitude:117.385257},{label:"临邑县",latitude:37.189798,value:371424,parentId:3714,longitude:116.8668},{label:"齐河县",latitude:36.783415,value:371425,parentId:3714,longitude:116.76281},{label:"平原县",latitude:37.165314,value:371426,parentId:3714,longitude:116.434056},{label:"夏津县",latitude:36.948371,value:371427,parentId:3714,longitude:116.001726},{label:"武城县",latitude:37.213311,value:371428,parentId:3714,longitude:116.069302},{label:"德州经济开发区",value:371471,parentId:3714},{label:"德州运河经济开发区",value:371472,parentId:3714},{label:"乐陵市",latitude:37.729907,value:371481,parentId:3714,longitude:117.231935},{label:"禹城市",latitude:36.933812,value:371482,parentId:3714,longitude:116.638327}]},{label:"聊城市",level:2,latitude:36.456703,value:3715,parentId:37,longitude:115.985371,children:[{label:"东昌府区",latitude:36.434645,value:371502,parentId:3715,longitude:115.988491},{label:"阳谷县",latitude:36.114392,value:371521,parentId:3715,longitude:115.79182},{label:"莘县",latitude:36.233598,value:371522,parentId:3715,longitude:115.671191},{label:"茌平县",latitude:36.456703,value:371523,parentId:3715,longitude:115.985371},{label:"东阿县",latitude:36.334917,value:371524,parentId:3715,longitude:116.24758},{label:"冠县",latitude:36.484009,value:371525,parentId:3715,longitude:115.44274},{label:"高唐县",latitude:36.846755,value:371526,parentId:3715,longitude:116.230158},{label:"聊城市经济开发区",value:371550,parentId:3715},{label:"聊城市高新技术产业开发区",value:371551,parentId:3715},{label:"聊城旅游度假区",value:371552,parentId:3715},{label:"临清市",latitude:36.838277,value:371581,parentId:3715,longitude:115.704881}]},{label:"滨州市",level:2,latitude:37.38199,value:3716,parentId:37,longitude:117.970703,children:[{label:"滨城区",value:371602,parentId:3716},{label:"沾化区",latitude:37.69926,value:371603,parentId:3716,longitude:118.098902},{label:"惠民县",latitude:37.489877,value:371621,parentId:3716,longitude:117.509921},{label:"阳信县",latitude:37.641106,value:371622,parentId:3716,longitude:117.578262},{label:"无棣县",latitude:37.77026,value:371623,parentId:3716,longitude:117.625696},{label:"博兴县",value:371625,parentId:3716},{label:"滨州市经济技术开发区",value:371650,parentId:3716},{label:"滨州高新区",value:371651,parentId:3716},{label:"滨州北海经济开发区",value:371652,parentId:3716},{label:"邹平市",value:371681,parentId:3716}]},{label:"菏泽市",level:2,latitude:35.23375,value:3717,parentId:37,longitude:115.480656,children:[{label:"牡丹区",latitude:35.252512,value:371702,parentId:3717,longitude:115.417827},{label:"定陶区",value:371703,parentId:3717},{label:"曹县",latitude:34.825508,value:371721,parentId:3717,longitude:115.542328},{label:"单县",latitude:34.778808,value:371722,parentId:3717,longitude:116.107428},{label:"成武县",latitude:34.952459,value:371723,parentId:3717,longitude:115.889765},{label:"巨野县",latitude:35.387374,value:371724,parentId:3717,longitude:116.065396},{label:"郓城县",latitude:35.599758,value:371725,parentId:3717,longitude:115.943613},{label:"鄄城县",latitude:35.563408,value:371726,parentId:3717,longitude:115.510193},{label:"东明县",latitude:35.289368,value:371728,parentId:3717,longitude:115.089905},{label:"菏泽经济技术开发区",value:371771,parentId:3717},{label:"菏泽高新技术开发区",value:371772,parentId:3717}]}]}],
				fileList:[],
				area:'',
				areaShow:false,
				provinceCode: "",
				provinceName: "",
				cityCode: "",	
				cityName: "",
				countyCode: "",
				countyName: "",
				updata:{moduleName:"stems-openapi"}


			}
		},
		
		onLoad(options){
			this.id=options.id;
			this.getFields();
			this.userInfo=check.checkLogin();
			console.log(this.UserInfo);
		},
		methods: {
			getFields:function(){
				request.post(api.fieldsList,{
					itemId:this.id,
					type:null,
				}).then(response=>{
					var formFields={};
					for(var i=0;i<response.data.data.length;i++){
						response.data.data[i].id="id_"+response.data.data[i].id
						formFields[response.data.data[i].id]='';
					}
					this.form=formFields;
					this.fields=response.data.data;
					
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试'
					})
				})
			},
			getFieldLength(str){
				return str.length*45;
			},
			selectDate(){
				this.calendarShow=true
			},
			selectArea(){
				this.areaShow=true
			},
			dateChange(e){
				console.log(e);
				this.recordDate=e.result;
			},
			areaConfirm(e){
				console.log(e);
				this.provinceName=e[0].label;
				this.provinceCode=e[0].value;
				this.cityName=e[1].label;
				this.cityCode=e[1].value;
				this.countyName=e[2].label;
				this.countyCode=e[2].value;
				this.area=this.provinceName+"-"+this.cityName+"-"+this.countyName;
			},
			submit:function(){
				 let files = [];
				 files = this.$refs.uUpload.lists;
				 let filesArr=[];
				 for(var i=0;i<files.length;i++){
					 let url=files[i].response.data;
					 filesArr.push(url);
				 }

				 console.log(filesArr);
				 
				 
				 let newForm={};
				 for(let key  in this.form){
					console.log(key + '---' + this.form[key])
					let newKeys=key.split("_");
					let newKey=newKeys[1];
					newForm[newKey]=this.form[key];
				 }
				
				request.post(api.fieldsSubmit,{
					provinceName:this.provinceName,
					provinceCode:this.provinceCode,
					cityName:this.cityName,
					cityCode:this.cityCode,
					countyName:this.countyName,
					countyCode:this.countyCode,
					itemId:this.id,
					userId:this.userInfo.uid,
					attachment:JSON.stringify(filesArr),
					title:this.title,
					recordDate:this.recordDate,
					createBy:this.userInfo.username,
					content:JSON.stringify(newForm),
				}).then(response=>{
					console.log(response);
					if(response.data.status==1){
						uni.showToast({
							icon:'none',
							title:'提交成功'
						})
						// uni.navigateTo({
						// 	url:'../list/list?id='+this.id
						// })
						uni.navigateBack({
							
						})
					}else{
						uni.showToast({
							icon:'none',
							title:'发生错误，请稍后再试'
						})
					}
				
			
				}).catch(ex=>{
					console.log(ex);
					uni.showToast({
						icon:'none',
						title:'请求失败，请稍后再试'
					})
				})
			},
			beforeUpload(index, list) {
				// 只上传偶数索引的文件
				list
				console.log(list);
			}

		}
	}
</script>

<style>
	.content {
		background-color:#FFFFFF;
		padding: 20rpx;
		min-height: 700px;
	}

	.form {
		background-color: #FFFFFF;
		padding: 20rpx;
	}

	.info_list_title {
		border-left: solid 10rpx #0095f0;
		padding: 0 10rpx;
		margin: 20rpx 0;
		font-size: 35rpx;
		font-weight: 500;
	}
</style>
